package com.smartleanx.module.hrm.intergration;

import com.smartleanx.framework.security.core.util.SecurityFrameworkUtils;
import com.smartleanx.module.bpm.api.definition.BpmModelApi;
import com.smartleanx.module.bpm.api.task.BpmProcessInstanceApi;
import com.smartleanx.module.bpm.api.task.BpmTaskApi;
import com.smartleanx.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO;
import com.smartleanx.module.bpm.api.task.dto.BpmProcessInstanceQueryReqDTO;
import com.smartleanx.module.bpm.api.task.dto.BpmProcessInstanceRespDTO;
import com.smartleanx.module.bpm.api.task.dto.BpmTaskRespDTO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 流程引擎
 *
 * @author tengcj
 * @date 2024/2/1
 */
@Component
public class BpmServiceProvider {

    @Resource
    private BpmProcessInstanceApi bpmProcessInstanceApi;

    @Resource
    private BpmTaskApi bpmTaskApi;

    @Resource
    private BpmModelApi bpmModelApi;

    public String createProcessInstance(BpmProcessInstanceCreateReqDTO createReqDTO) {
        return bpmProcessInstanceApi.createProcessInstance(SecurityFrameworkUtils.getLoginUserId(), createReqDTO).getCheckedData();
    }

    public List<BpmTaskRespDTO> getTaskListByProcessInstanceId(String processInstanceId) {
        return bpmTaskApi.getTaskListByProcessInstanceId(processInstanceId).getCheckedData();
    }

    public BpmProcessInstanceRespDTO getProcessInstance(String processInstanceId) {
        BpmProcessInstanceQueryReqDTO queryReqDTO = new BpmProcessInstanceQueryReqDTO();
        queryReqDTO.setProcessInstanceId(processInstanceId);
        return bpmProcessInstanceApi.getProcessInstance(queryReqDTO).getCheckedData();
    }

    public Boolean initBpmModel() {
        return bpmModelApi.initForHrm().getCheckedData();
    }

    public Boolean initBpmModelNew() {
        return bpmModelApi.initForHrmNew().getCheckedData();
    }

    /**
     * TODO 下次发版结束后删除此接口
     */
    public Boolean reInitBpmModel() {
        return bpmModelApi.reInitForHrm().getCheckedData();
    }

}
